﻿using MediatR;
using Medical.Api.Read.Application.Command.PackagingSterilization;
using Medical.Api.Read.Dto.PackagingSterilization;
using Medical.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Medical.Api.Read.Controllers
{
    /// <summary>
    /// 包装灭菌
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PackagingSterilizationController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PackagingSterilizationController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取包装登记列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<PackagingSterilizationDTo>>> GetPackagingSterilization([FromQuery]GetPackagingSterilizationCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取待灭菌列表信息
        /// </summary>
        /// <returns>待灭菌列表信息</returns>
        [HttpGet]
        public async Task<ApiResult<List<sterilizationDtos>>> GetToBeSterilizedList()
        {
            try
            {
                var command = new GetToBeSterilizedCommand();
                var result = await mediator.Send(command);
                return result;
            }
            catch (System.Exception ex)
            {
                return new ApiResult<List<sterilizationDtos>>
                {
                    Code = ApiEnums.Error,
                    Msg = "获取待灭菌列表信息失败：" + ex.Message,
                    Data = null
                };
            }
        }
        
        /// <summary>
        /// 获取已完成灭菌信息列表
        /// </summary>
        /// <returns>已完成灭菌信息列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<sterilizationDtos>>> GetSterilizedList()
        {
            try
            {
                var command = new GetSterilizedCommand();
                var result = await mediator.Send(command);
                return result;
            }
            catch (System.Exception ex)
            {
                return new ApiResult<List<sterilizationDtos>>
                {
                    Code = ApiEnums.Error,
                    Msg = "获取已完成灭菌信息失败：" + ex.Message,
                    Data = null
                };
            }
        }
        
    }
}
